package com.qiaofang.collectmanage.task;
import com.github.ltsopensource.core.domain.Action;
import com.github.ltsopensource.core.logger.Logger;
import com.github.ltsopensource.core.logger.LoggerFactory;
import com.github.ltsopensource.tasktracker.Result;
import com.github.ltsopensource.tasktracker.runner.JobContext;
import com.github.ltsopensource.tasktracker.runner.JobRunner;
import com.qiaofang.collectmanage.constants.SecretaryCollectTypeEnum;
import com.qiaofang.collectmanage.dao.util.DateUtils;
import com.qiaofang.collectmanage.service.CollectQualityService;
import com.qiaofang.collectmanage.service.SecretaryService;
import com.qiaofang.collectmanage.stub.request.SecretaryRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author
 */
@Component
public class CrawlerSecretaryDataRunner implements JobRunner{

    private final Logger logger = LoggerFactory.getLogger(CrawlerSecretaryDataRunner.class);

    @Autowired
    SecretaryService secretaryService;

    @Override
    public Result run(JobContext jobContext) {
        try {
            Date date = new Date();
            logger.info("now time:" + DateUtils.formatDate(date, DateUtils.YYYY_MM_DD_HH_MM_SS));
            String nowDate = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
            String belonger = SecretaryCollectTypeEnum.PERSONAL.getName();
            String collectHouseType = SecretaryCollectTypeEnum.COLLECT_HOUSE_TYPE.getName();
            // 出租
            SecretaryRequest secretaryRequestRent = new SecretaryRequest();
            secretaryRequestRent.setBelonger(belonger);
            secretaryRequestRent.setCollectHouseType(collectHouseType);
            secretaryRequestRent.setStartTime(nowDate);
            secretaryRequestRent.setEndTime(nowDate);
            String collectType = SecretaryCollectTypeEnum.RENT.getName();
            secretaryRequestRent.setCollectType(collectType);
            secretaryService.crawlerSecretaryHouseInfo(secretaryRequestRent);

            // 出售
            String collectTypeSale = SecretaryCollectTypeEnum.SALE.getName();
            SecretaryRequest secretaryRequestSale = new SecretaryRequest();
            secretaryRequestSale.setBelonger(belonger);
            secretaryRequestSale.setCollectHouseType(collectHouseType);
            secretaryRequestSale.setStartTime(nowDate);
            secretaryRequestSale.setEndTime(nowDate);
            secretaryRequestSale.setCollectType(collectTypeSale);
            secretaryService.crawlerSecretaryHouseInfo(secretaryRequestSale);
        } catch(Exception e){
            e.printStackTrace();
        }
        return new Result(Action.EXECUTE_SUCCESS, this.getClass() + " SUCCESS");
    }

}
